package  
{
	import flash.display.Sprite;
	import flash.geom.Point;
	/**
	 * ...
	 * @author Lorenzo Nuvoletta
	 */
	public class Actor extends Sprite
	{
		private var _w			:Number;
		private var _h			:Number;
		private var _type		:uint;
		
		public var directionX	:Number = 10;
		public var directionY	:Number = 10;
		
		public static const STRAIGHT_CIRCLES	:uint = 1;
		public static const SIN_CIRCLES			:uint = 2;
		private var rot:int;
		private var p:Point;
		
		public function Actor(w:Number, h:Number, type:uint) 
		{			
			_type = type;
			_w = w;
			_h = h;
			this.x = Math.random() * _w;
			this.y = Math.random() * _h;
			p = new Point(this.x, this.y);
			update();			
		}
		
		public function update():void {
			switch(_type) {
				
				case STRAIGHT_CIRCLES:
					this.x += directionX;
					this.y += directionY;
					
					if (this.x < 0 || this.x > _w) directionX*=-1;
					if (this.y < 0 || this.y > _h) directionY*=-1;
					
					this.graphics.clear();
					this.graphics.beginFill((Math.random() * 0x0011AA) + 0xFFEE00, Math.random());
					this.graphics.drawCircle(0, 0, Math.random() * 20);
					this.graphics.endFill();
					break;
					
				case SIN_CIRCLES:
					rot += 10;
					
					var _alpha:Number = Math.random();
					var modifier:int = 1;
					
					if ( (directionX > 0 && directionY > 0) || (directionX < 0 && directionY < 0) ) {
						modifier = -1;
					}
					
					p.x += directionX/2;
					p.y += directionY/2;
					
					this.x = (Math.sin(toRadians(rot)) * 50) + p.x;
					this.y = (modifier * (Math.sin(toRadians(rot)) * 50)) + p.y;					
					
					if (p.x < 0 || p.x > _w) directionX*=-1;
					if (p.y < 0 || p.y > _h) directionY*=-1;
					
					this.graphics.clear();
					this.graphics.beginFill(Math.random() * 0xFFFFFF, _alpha);
					this.graphics.drawCircle(0, 0, Math.random() * 20);
					this.graphics.endFill();
					break;
					
			}
		}
		
		private function toRadians(n:Number):Number {
			return n * Math.PI / 180;
		}
		
	}

}